package com.spundhan.xtrac.fragments;

import com.aretha.slidemenu.SlideMenu;
import com.spundhan.xtrac.ExpensesActivity;
import com.spundhan.xtrac.MainActivity;
import com.spundhan.xtrac.R;
import com.spundhan.xtrac.ReportsActivity;
import com.spundhan.xtrac.SettingsActivity;
import com.spundhan.xtrac.TripsActivity;
import com.spundhan.xtrac.adapters.MenuListAdapter;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class SlideMenuListFragment extends Fragment {

	ListView listOfOptions;
	
	MenuListAdapter adapter;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.fragment_side_menu,
				container, false);
		listOfOptions = (ListView) rootView.findViewById(R.id.list_options);
		listOfOptions.setOnItemClickListener(listener);

		return rootView;

	}
	
	@Override
	public void onStart() {
		super.onStart();
		
		adapter = new MenuListAdapter(getActivity(), R.layout.menu_list_row,R.id.text_option);
		listOfOptions.setAdapter(adapter);
	}
	
	OnItemClickListener listener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {

			switch (position) {
			case 0:
//				MainActivity.close();
//				MainActivity.activity.finish();
				startActivity(new Intent(getActivity(), TripsActivity.class));
				getActivity().overridePendingTransition(R.anim.left_to_right, R.anim.abc_fade_out);
				break;
			case 1:
//				MainActivity.close();
				startActivity(new Intent(getActivity(), ExpensesActivity.class));
				getActivity().overridePendingTransition(R.anim.left_to_right, R.anim.abc_fade_out);
				break;
			case 2:
//				MainActivity.close();
				startActivity(new Intent(getActivity(), ReportsActivity.class));
				getActivity().overridePendingTransition(R.anim.left_to_right, R.anim.abc_fade_out);
				break;
			case 3:
//				MainActivity.close();
				startActivity(new Intent(getActivity(), SettingsActivity.class));
				getActivity().overridePendingTransition(R.anim.left_to_right, R.anim.abc_fade_out);
				break;

			default:
				break;
			}
		}
	};
}
